//
//  GRCollectionCommonViewCell.m
//  YC_GRice
//
//  Created by Feng Liu on 2018/8/31.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRCollectionCommonViewCell.h"

@implementation GRCollectionCommonViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.deleteBtn.backgroundColor           = KGMBACKGROUND_COLOR;
    self.deleteBtn.titleLabel.numberOfLines = 0;
    self.deleteBtn.titleLabel.font               = [UIFont systemFontOfSize:14];
    [self.deleteBtn setTitle:@"取\n消\n收\n藏" forState:UIControlStateNormal];
    [self.deleteBtn setTitleColor:KGMGRAY_COLOR forState:UIControlStateNormal];
    [self.deleteBtn addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.deleteBtn];
    
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.bottom.mas_equalTo(self.contentView);
        make.left.mas_equalTo(self.contentView.mas_right);
        make.width.mas_equalTo(50);
    }];
}

-(void)setCollectModel:(GRCollectCommonModel *)collectModel {
    _collectModel = collectModel;
}

- (void)showCancle:(BOOL)cancle {
    WEAKSELF
    [UIView animateWithDuration:.3 animations:^{
        weakSelf.deleteBtn.x = cancle ? KscreenWidth -50 : KscreenWidth;
    } completion:^(BOOL finished) {
        weakSelf.collectModel.showCancleButton = cancle;
    }];
}

- (void)deleteAction:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(deleteRowAtTableViewCell:)]) {
        [self.delegate deleteRowAtTableViewCell:self];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
